<template>
	<div>
		<view class="wrap-head">
			<view class="title">请输入任意条件进行查询</view>
			
			<view class="search-bg">
				<input v-model="keyword" placeholder="请输入姓名、参赛号、证件号进行查询" placeholder-class="place" />
			</view>
			
			<view class="check" @click="onCheck">
				查询
			</view>
		</view>
		
		<view class="wrap">
			<view class="wrap-list">
				<block v-for="(item, index) in list" :key="index">
					<view class="item">
						<view class="file">
							<image :src="getImageURL(item.cover)" lazy-load @error="onImageError(index)" />
							<view class="status">
								{{ getStatus(item.process) }}
							</view>
						</view>
				
						<view class="right">
							<view class="title">{{ item.title }}</view>
				
							<!-- <view class="scrip">{{ item.title }}</view> -->
				
							<view class="bottom">
								<view class="left">
									<view class="address-bg">
										<image src='/static/images/area.png' />
										<view>{{ item.address }}</view>
									</view>
				
									<view class="time-bg">
										<image src='../../static/images/date.png' />
										<view>{{ item.createAt }}</view>
									</view>
								</view>
				
								<view class="btn"> {{ getBtnText(item.process) }} </view>
							</view>
						</view>
					</view>
				</block>
			</view>
		
			<view class="no-data" v-if="list.length == 0">
				<image class="img" src="../../static/images/check_noData.png" />
				
				<view class="name">你好，你未加入赛事，快来参加吧！</view>
			</view>
		</view>
	</div>
</template>

<script>
	import { getMyCompetitionData } from "@/utils/api";
	export default {
		data() {
			return {
				keyword: "",
				page: 1,
				total: 0,
				list: [],
			}
		},
		onLoad() {
			this.onRefresh()
		},
		onPullDownRefresh() {
			this.onRefresh()
		},
		onReachBottom() {
			if (this.list.length < this.total) {
				this.page++;
				this.getData()
			}
		},
		methods: {
			/**
			 * 图片加载失败
			 */
			onImageError(index) {
				this.list[index].cover = "/static/common/default_icon.png";
			},
			/**
			 * 获取按钮
			 */
			getBtnText(status) {
				let text = "";
				if (status == 0) {
					text = "参赛";
				} else if (status == 1) {
					text = "参赛中";
				} else if (sttaus == 2) {
					text = "成绩";
				}
				return text;
			},
			/**
			 * 查询
			 */
			onCheck() {
				this.onRefresh()
			},
			/**
			 * 刷新
			 */
			onRefresh() {
				this.page = 1;
				this.list = [];
				this.getData();
			},
			/**
			 * 网络请求
			 */
			getData() {
				getMyCompetitionData(this.page, this.keyword).then((res) => {
					this.total = res.data.total;
					const list = res.data.data;
					if (this.page === 1) {
						this.list = list;
					} else {
						this.list = this.list.concat(list);
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #F6F6F6;
	}
	.wrap-head {
		position: sticky;
		left: 0;
		top: 0;
		width: 100%;
		background-color: #F6F6F6;
		z-index: 10;
		display: flex;
		flex-direction: column;
		align-items: center;
		overflow: hidden;
		padding: 60rpx 50rpx 10rpx;
		box-sizing: border-box;
		
		.title {
			color: #333333;
			font-size: 34rpx;
			font-weight: bold;
		}
		
		.search-bg {
			margin-top: 40rpx;
			background-color: white;
			border-radius: 10rpx;
			width: 650rpx;
			height: 84rpx;
			box-sizing: border-box;
			padding: 10rpx 20rpx;
			display: flex;
			align-items: center;
			
			input {
				width: 100%;
				height: 100%;
				text-align: center;
				font-size: 26rpx;
				color: #333;
			}
			
			.place {
				color: #999999;
			}
		}
		
		.check {
			margin-top: 30rpx;
			width: 650rpx;
			height: 84rpx;
			background-color: #EA5520;
			border-radius: 42rpx;
			line-height: 84rpx;
			text-align: center;
			color: white;
			font-size: 30rpx;
		}
	}
	
	.wrap {
		width: 100%;
		overflow: hidden;
		
		.wrap-list {
			width: 100%;
			overflow: hidden;
			background-color: white;
			padding: 0 30rpx;
			box-sizing: border-box;
		
			.item {
				width: 100%;
				overflow: hidden;
				padding: 30rpx 0;
				border-bottom: 2rpx solid#E5E5E5;
				display: flex;
				align-items: center;
		
				&:last-child {
					border-bottom: none;
				}
		
				.file {
					width: 280rpx;
					height: 186rpx;
					position: relative;
					z-index: 1;
					overflow: hidden;
		
					> image {
						width: 100%;
						height: 100%;
					}
		
					.status {
						position: absolute;
						left: 0;
						top: 0;
						z-index: 2;
						width: 116rpx;
						height: 44rpx;
						line-height: 44rpx;
						text-align: center;
						border-bottom-right-radius: 20rpx;
						overflow: hidden;
						background-color: rgba($color: #ea5520, $alpha: 0.5);
						color: white;
						font-size: 24rpx;
					}
				}
				.right {
					margin-left: 25rpx;
					flex: 1;
					overflow: hidden;
		
					.title {
						color: #333;
						font-size: 30rpx;
						font-weight: bold;
					}
		
					.scrip {
						margin-top: 20rpx;
						color: #666666;
						font-size: 26rpx;
					}
		
					.bottom {
						margin-top: 20rpx;
						width: 100%;
						overflow: hidden;
						display: flex;
						align-items: center;
						justify-content: space-between;
		
						.left {
							flex: 1;
							overflow: hidden;
		
							.address-bg {
								width: 100%;
								overflow: hidden;
								display: flex;
								align-items: center;
		
								> image {
									width: 26rpx;
									height: 25rpx;
								}
								> view {
									margin-left: 13rpx;
									color: #999999;
									font-size: 24rpx;
								}
							}
							.time-bg {
								margin-top: 20rpx;
								width: 100%;
								overflow: hidden;
								display: flex;
								align-items: center;
								> image {
									width: 24rpx;
									height: 24rpx;
								}
								> view {
									margin-left: 14rpx;
									color: #999999;
									font-size: 24rpx;
								}
							}
						}
		
						.btn {
							margin-left: 10rpx;
							width: 126rpx;
							height: 56rpx;
							line-height: 56rpx;
							text-align: center;
							border-radius: 30rpx;
							overflow: hidden;
							background-color: #ea5520;
							color: white;
							font-size: 26rpx;
							display: flex;
							align-items: center;
							justify-content: center;
						}
					}
				}
			}
		}
	
		.no-data {
			width: 100%;
			padding: 60rpx 0;
			overflow: hidden;
			display: flex;
			flex-direction: column;
			align-items: center;
			
			.img {
				width: 473rpx;
				height: 341rpx;
			}
			
			.name {
				margin-top: 22rpx;
				color: #333;
				font-size: 30rpx;
				font-weight: bold;
			}
		}
	
	}
	
	
	
	
	
	
	
	
	
	
	
	view {
		line-height: 1;
	}
</style>